import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    meta: {
      title: "用户登录"
    }
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '首页', icon: 'el-icon-pie-chart'}
    }]
  },

  {
    path: '/department',
    component: Layout,
    redirect: '/department/list',
    name: 'Department',
    meta: {title: '院系管理', icon: 'el-icon-film', permission: "sys:department:manager"},
    children: [
      {
        path: 'list',
        name: 'DepartmentList',
        component: () => import('@/views/department/list'),
        meta: {title: '院系列表', icon: 'el-icon-document', permission: "sys:department:list"}
      },
      {
        path: 'add',
        name: 'departmentAdd',
        component: () => import('@/views/department/add'),
        meta: {title: '添加院系', icon: 'el-icon-news', permission: "sys:department:add"}
      }
    ]
  },
  {
    path: '/student',
    component: Layout,
    redirect: '/student/list',
    name: 'Student',
    meta: {title: '学生管理', icon: 'el-icon-user', permission: "sys:student:manager"},
    children: [
      {
        path: 'list',
        name: 'StudentList',
        component: () => import('@/views/student/list'),
        meta: {title: '学生列表', icon: 'el-icon-document', permission: "sys:student:list"}
      },
      {
        path: 'add',
        name: 'studentAdd',
        component: () => import('@/views/student/add'),
        meta: {title: '添加学生', icon: 'el-icon-news', permission: "sys:student:add"}
      }
    ]
  },
  {
    path: '/book',
    component: Layout,
    redirect: '/book/list',
    name: 'Book',
    meta: {title: '图书管理', icon: 'el-icon-reading', permission: "sys:book:manager"},
    children: [
      {
        path: 'list',
        name: 'BookList',
        component: () => import('@/views/book/list'),
        meta: {title: '图书列表', icon: 'el-icon-document', permission: "sys:book:list"}
      },
      {
        path: 'add',
        name: 'bookAdd',
        component: () => import('@/views/book/add'),
        meta: {title: '添加图书', icon: 'el-icon-news', permission: "sys:book:add"}
      }
    ]
  },
  {
    path: '/rbac',
    component: Layout,
    name: 'rbac',
    meta: {
      title: 'RBAC管理',
      icon: 'el-icon-lock', permission: "sys:rbac:manager"
    },
    children: [
      {
        path: 'user',
        component: () => import('@/views/rbac/index'), // Parent router-view
        name: 'user',
        redirect: '/rbac/user/list',
        meta: {title: '用户管理', icon: 'user', permission: "sys:rbac:user:manager"},
        children: [
          {
            path: 'list',
            component: () => import('@/views/rbac/user/list'),
            name: 'UserList',
            meta: {title: '用户列表', icon: 'userlist', permission: "sys:rbac:user:list"}
          },
          {
            path: 'add',
            component: () => import('@/views/rbac/user/add'),
            name: 'UserAdd',
            meta: {title: '添加用户', icon: 'adduser', permission: "sys:rbac:user:add"},
          },
        ]
      },
      {
        path: 'role',
        component: () => import('@/views/rbac/index'), // Parent router-view
        name: 'role',
        redirect: '/rbac/role/list',
        meta: {title: '角色管理', icon: 'role', permission: "sys:rbac:role:manager"},
        children: [
          {
            path: 'list',
            component: () => import('@/views/rbac/role/list'),
            name: 'RoleList',
            meta: {title: '角色列表', icon: 'roleList', permission: "sys:rbac:role:list"}
          },
          {
            path: 'add',
            component: () => import('@/views/rbac/role/add'),
            name: 'RoleAdd',
            meta: {title: '添加角色', icon: 'roleAdd', permission: "sys:rbac:role:add"},
          },
        ]
      },
      {
        path: 'permission',
        component: () => import('@/views/rbac/index'), // Parent router-view
        name: 'permission',
        redirect: '/rbac/permission/list',
        meta: {title: '权限管理', icon: 'el-icon-key', permission: "sys:rbac:permission:manager"},
        children: [
          {
            path: 'list',
            component: () => import('@/views/rbac/permission/list'),
            name: 'PermissionList',
            meta: {title: '权限列表', icon: 'el-icon-document', permission: "sys:rbac:permission:list"}
          },
          {
            path: 'add',
            component: () => import('@/views/rbac/permission/add'),
            name: 'PermissionAdd',
            meta: {title: '添加权限', icon: 'el-icon-news', permission: "sys:rbac:permission:add"},
          },
        ]
      },
    ]
  },

  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const router = new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})


export default router
